gtk-demo: Improve text scroll example
authorMatthias Clasen <mclasen@redhat.com>
Mon, 21 Jul 2014 10:40:12 +0000 (06:40 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 21 Jul 2014 15:18:10 +0000 (11:18 -0400)
Add numbers, so the lines can be differentiated, even if they
don't move on screen.

demos/gtk-demo/textscroll.c

index 3eaa1f99d014b481488f68efc6a54d780c59ce73..90ae13b5ee17b9b5f0cd579c6e0595f13546102c 100644 (file)
@@ -16,6 +16,7 @@ scroll_to_end (GtkTextView *textview)
   GtkTextIter iter;
   GtkTextMark *mark;
   char *spaces;
+  char *text;
   static int count;
 
   buffer = gtk_text_view_get_buffer (textview);
@@ -32,11 +33,11 @@ scroll_to_end (GtkTextView *textview)
   spaces = g_strnfill (count++, ' ');
   gtk_text_buffer_insert (buffer, &iter, "\n", -1);
   gtk_text_buffer_insert (buffer, &iter, spaces, -1);
-  gtk_text_buffer_insert (buffer, &iter,
-                          "Scroll to end scroll to end scroll "
-                          "to end scroll to end ",
-                          -1);
+  text = g_strdup_printf ("Scroll to end scroll to end scroll "
+                          "to end scroll to end %d", count);
+  gtk_text_buffer_insert (buffer, &iter, text, -1);
   g_free (spaces);
+  g_free (text);
 
   /* Now scroll the end mark onscreen.
    */
@@ -60,6 +61,7 @@ scroll_to_bottom (GtkTextView *textview)
   GtkTextIter iter;
   GtkTextMark *mark;
   char *spaces;
+  char *text;
   static int count;
 
   buffer = gtk_text_view_get_buffer (textview);
@@ -73,11 +75,11 @@ scroll_to_bottom (GtkTextView *textview)
   spaces = g_strnfill (count++, ' ');
   gtk_text_buffer_insert (buffer, &iter, "\n", -1);
   gtk_text_buffer_insert (buffer, &iter, spaces, -1);
-  gtk_text_buffer_insert (buffer, &iter,
-                          "Scroll to bottom scroll to bottom scroll "
-                          "to bottom scroll to bottom",
-                          -1);
+  text = g_strdup_printf ("Scroll to bottom scroll to bottom scroll "
+                          "to bottom scroll to bottom %d", count);
+  gtk_text_buffer_insert (buffer, &iter, text, -1);
   g_free (spaces);
+  g_free (text);
 
   /* Move the iterator to the beginning of line, so we don't scroll
    * in horizontal direction